<?php
/**
 * Description
 *
 * PHP version 7
 *
 * @category Custom
 * @package  Custom
 * @author   ryu <mo5467@126.com>
 * @date     2020-04-28 00:22:14
 * @lastTime 2020-05-01 23:13:46
 * @license  https://opensource.org/licenses/MIT MIT License
 * @link     none
 */
namespace Test\Unit;

use Design\Behavioral\Command\Invoker;
use Design\Behavioral\Command\Receiver;
use Design\Behavioral\Command\HelloCommand;
use Design\Behavioral\Command\AddMessageDateCommand;

class CommandTest extends \Test\BaseTest
{


    public function testInvocation()
    {
        $receiver = new Receiver();
        $invoker  = new Invoker();

        $invoker->setCommand(new HelloCommand($receiver));
        $invoker->run();

        $this->assertSame('Hello World', $receiver->getOutput());

        $addMessageDateCommand = new AddMessageDateCommand($receiver);
        $addMessageDateCommand->execute();
        $invoker->run();

        $this->assertSame("Hello World\nHello World [".Date('Y-m-d')."]", $receiver->getOutput());

        $addMessageDateCommand->undo();
        $invoker->run();

        $this->assertSame("Hello World\nHello World [".Date('Y-m-d')."]\nHello World", $receiver->getOutput());

    }//end testInvocation()


}//end class
